/**
 * 微信端个人中心-我的钱包
 */
$(function(){
	// 上拉加载更多（分页）
	$(window).on('scroll',function(){
	    if($(window).scrollTop()>=$(document).height()-$(window).height()){
	    	//显示加载中效果
	    	$("#loadContent").show();
	    	//获取当前页码
	    	var page_count = $("#page_count").val();
	    	//总页数
	    	var page_total = $("#page_total").val();
//	    	alert(page_count);
//	    	alert(page_total);
	    	if(parseInt(page_count) >= parseInt(page_total)){
	    		$("#noContent").show();
	    		$("#loadContent").hide();
	    		return false;
	    	}
	    	//查询参数
	    	var params = "page="+(parseInt(page_count)+1);
	    	//获取支付类型参数
	    	var payType = $("#payType").val()
	    	if(payType){
	    		params += "&payType="+payType;
	    	}
	    	//查询请求URL
			var url = rootPath + "/wx/my/wxWallet/searchWalletFlow";
			$.ajax({
				type : "post",
				url : url,
				data : params,
				datatype : "json",
				success : function(json) {
					//从后台传递过来的是json字符串，使用JSON.parse把json字符串转化成json对象
					var jsonObject = JSON.parse(json);
					//获取按月份统计汇总数据(json)
					var statJson = jsonObject.statList;
					//解析统计数据并且拼接HTML
					for(var i =0; i<statJson.length;i++){
						//按月统计支出以及收入对象（每次只取一个月即一条统计数据）
						var walletStat = statJson[i];
						//拼接HTML
						var walletStatHtml = "<div class=\"hd\">"+
								                	"<div class=\"hd_con\">"+
								                	"<div class=\"left\">"+
								                    	"<strong>"+walletStat.month+"</strong>"+
								                    	"<b>支出 ￥"+walletStat.outMoney+" 元<i></i>收入 ￥"+walletStat.inMoney+" 元</b>"+
								                    	"</div>"+
														"</div></div>";
						$("#content").append($(walletStatHtml));
					}
					
					//某一月份下的钱包流水
					var walletJson = jsonObject.walletFlowList;
					//拼接客户钱包流水记录
					var walletHtml = "<div class=\"jf_list\"><ul>";
					for(var j=0;j<walletJson.length;j++){
						//客户钱包流水对象
						var wallet = walletJson[j];
						//拼接HTML
						walletHtml += "<li><div class=\"boxs_1\">";
				         if(wallet.flowType==1){
				                walletHtml += "<div class=\"pic\">"+
				                    	"<img src=\""+rootPath+"/statics_wx/images/zjtx.png\" />"+
				                    "</div>"+
				                    "<div class=\"item-info\">"+
				                    	"<h2>提现</h2>"+
				                    	"<h3>[支出]</h3>"+
				                        "<h4>"+wallet.payTimeStr+"</h4>"+
				                        "<p class=\"a1\">-"+wallet.outMoney+"</p>"+
				                    "</div>";
				          }else if(wallet.flowType==2){
				        	  	walletHtml += "<div class=\"pic\">"+
			                    	"<img src=\""+rootPath+"/statics_wx/images/tjxd.png\" />"+
				                    "</div>"+
				                    "<div class=\"item-info\">"+
				                    	"<h2>推荐下单</h2>"+
				                    	"<h3>[收入]</h3>"+
				                        "<h4>"+wallet.payTimeStr+"</h4>"+
				                        "<p class=\"a2\">+"+wallet.inMoney+"</p>"+
				                    "</div>";
				          }else if(wallet.flowType==3){
				        	  	walletHtml += "<div class=\"pic\">"+
			                    	"<img src=\""+rootPath+"/statics_wx/images/ddxf.png\" />"+
				                    "</div>"+
				                    "<div class=\"item-info\">"+
				                    	"<h2>订单支付</h2>"+
				                    	"<h3>[支出]</h3>"+
				                        "<h4>"+wallet.payTimeStr+"</h4>"+
				                        "<p class=\"a1\">-"+wallet.outMoney+"</p>"+
				                    "</div>";
				            }
				         walletHtml += "</li>";
					}
					walletHtml += "</ul></div>";
					$("#content").append($(walletHtml));
					//数据加载完成，隐藏加载中特效
					$("#loadContent").hide();
					//加载成功后把当前页码更新
					$("#page_count").val(parseInt(page_count)+1)
				},
				error : function() {
					layer.msg('查询失败',{time:1000});
				}
			});
	    }
	})
	
	//“支出”点击事件
	$("#expend").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWallet/toMyWallet?payType=0";
	})
	
	//“收入点击事件”
	$("#income").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWallet/toMyWallet?payType=1";
	})
	
	//“全部”点击事件
	$("#allwallet").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWallet/toMyWallet";
	})
	
	//提现按钮点击事件
	$("#withdrawBth").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWalletWithdraw/toSelectAccountType";
	})
});